home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / window / ultrawin / uwdemo / start_2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-02  |  9.1 KB  |  204 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /* START_2.C                                                                */
  4. /*                                                                          */
  5. /*     This C skeleton program was written to show you how to get up and    */
  6. /* running quickly with the UltraWin library.  But first, allow me to       */
  7. /* explain a little about the techniques we use.                            */
  8. /*                                                                          */
  9. /*     UltraWin was written with two "levels" in mind.  The first level     */
  10. /* includes the routines that do all the down and dirty work of windowing.  */
  11. /* The START_1.C file contains a demonstration showing how to use the       */
  12. /* lowest level functions in an application.                                */
  13. /*                                                                          */
  14. /*     The second layer is what we call the window manager.  This is the    */
  15. /* really slick part of UltraWin, as this provides capabilities to write    */
  16. /* to any window at any time, regardless of overlap!  This layer is dealt   */
  17. /* with in this skeleton program.                                           */
  18. /*                                                                          */
  19. /*     The main thing to remember when using the window manager is never    */
  20. /* to call wn_destroy(), as the function remove_window() will call it for   */
  21. /* you.                                                                     */
  22. /*                                                                          */
  23. /*                                                          Boyd Gafford    */
  24. /*                                                          EnQue Software  */
  25. /*                                                          12/18/90        */
  26. /*                                                                          */
  27. /****************************************************************************/
  28. #include <ctype.h>
  29. #include "uw.h"                            /* include the necessary headers */
  30. #include "uw_globx.h"
  31. #include "uw_keys.h"
  32.  
  33.  
  34. #define   MAX_WINDOWS    8
  35.  
  36. /*----------------------- global window variables --------------------------*/
  37. WINDOW    Desk_window;                    /* global window for "desktop"    */
  38. WINDOW    Win_array[MAX_WINDOWS];         /* eight little windows to add    */
  39.  
  40. /*------------------------------ prototypes --------------------------------*/
  41. int back_func();
  42.  
  43. /**************/
  44. /* ~back_func */
  45. /*            ***************************************************************/
  46. /* This function is called during idle time.  If you wanted to do some      */
  47. /* background processing, then put it here!!!                               */
  48. /****************************************************************************/
  49. int back_func()
  50. {
  51.   int i;
  52.  
  53.   for (i=0; i<MAX_WINDOWS; i++)
  54.         wn_st("UltraWin ", &Win_array[i]);
  55.     return(1);
  56. }
  57. /*** end of back_func ***/
  58.  
  59. /*********/
  60. /* ~main */
  61. /*       ********************************************************************/
  62. /* This is the main routine, which does the simple skeleton demo!           */
  63. /****************************************************************************/
  64. int main()
  65. {
  66.   int i, x1, y1, x2, y2, width, height;
  67.  
  68.  
  69.   init_video(80, 50);
  70.  
  71.   /* This function initializes the window library, and sets the screen to   */
  72.   /* 80 columns and 50 rows.  After the function call, the global variables */
  73.   /* V_cols will contain the actual number of columns on the screen, and    */
  74.   /* V_rows will contain the actual number of rows.  If you have a VGA      */
  75.   /* board, you will get V_cols = 80 and V_rows = 50.  If you have an EGA   */
  76.   /* board, you will get V_cols = 80 and V_rows = 43.  If you just have CGA */
  77.   /* you will get V_cols = 80 and V_rows = 25.  If you wanted to use the    */
  78.   /* 80x25 screen on ANY board, just use init_video(80, 25).                */
  79.   /* Also please note that if you want to use the mouse in this program,    */
  80.   /* the call to init_mouse() would be next! (refer to START_1.C)           */
  81.  
  82.  
  83.     init_clock(0x3333);
  84.  
  85.     /* This function takes over the PC clock, setting the timer interrupt to  */
  86.     /* occur 91 times a second.  Once this call is made, you can use any of   */
  87.     /* the UltraWin user timers, or the tone() function.  You do not have to  */
  88.     /* call this if you are not going to use any of the UltraWin PC timer     */
  89.     /* routines.                                                              */
  90.  
  91.  
  92.     wn_create(0, 0, V_cols-1, V_rows-1, SLD_BDR, WN_NORMAL, &Desk_window);
  93.   randomize();
  94.   for (i=0; i<MAX_WINDOWS; i++)
  95.   {
  96.     width = random(30) + 15;
  97.     height = random(16) + 5;
  98.     x1 = random(V_cols - width);
  99.     y1 = random(V_rows - height);
  100.     x2 = x1 + width - 1;
  101.     y2 = y1 + height - 1;
  102.     wn_create(x1, y1, x2, y2, SLD_BDR, WN_NORMAL, &Win_array[i]);
  103.   }
  104.  
  105.   /* Create the desktop window, and all the windows to be added.  Please    */
  106.   /* note that we do not have to create ANY of the windows as WN_POPUP, as  */
  107.   /* the window manager takes care of all window refresh/redraw!            */
  108.   /* (WN_NORMAL windows also take less RAM, since what is behind them does  */
  109.   /* not have to be saved.)                                                 */
  110.  
  111.  
  112.   wn_color(WHITE, BLUE, &Desk_window);
  113.   for (i=0; i<MAX_WINDOWS; i++)
  114.     wn_color(WHITE, i % 8, &Win_array[i]);
  115.  
  116.   /* Set the color of all the windows in question.                          */
  117.  
  118.  
  119.   wn_bdr_color(WHITE, BLUE, &Desk_window);
  120.   for (i=0; i<MAX_WINDOWS; i++)
  121.     wn_bdr_color((i % 8) + 8, i % 8, &Win_array[i]);
  122.  
  123.   /* Set the border color of all the windows in question.                   */
  124.  
  125.  
  126.   wn_name("[ Desktop Window ]", &Desk_window);
  127.  
  128.   /* Set the title of the back window to something kind of descriptive.     */
  129.  
  130.  
  131.   add_window(&Desk_window);
  132.  
  133.   /* this call will put the Desk_window on the screen!                      */
  134.  
  135.  
  136.   for (i=0; i<MAX_WINDOWS; i++)
  137.     add_window(&Win_array[i]);
  138.  
  139.   /* Add each of the windows to the linked list.  Notice that a call to     */
  140.   /* the lower level wn_set() is not necessary! ( add_window() does it for  */
  141.   /* you! )                                                                 */
  142.  
  143.   /* NOTE:  If you want to do a "popup" window with the window manager, all */
  144.   /* you have to do is create it the size you wish with wn_create(), then   */
  145.   /* set the colors with wn_color() and wn_bdr_color(), then call the       */
  146.   /* add_window() function to place it on the screen!  When you are finished*/
  147.   /* with the window, just call remove_window().  The screen will be updated*/
  148.   /* and you don't have to worry about a thing.  Morover, you can create    */
  149.   /* your popup window with the WN_NORMAL define!  You don't have to define */
  150.   /* the window as a WN_POPUP type as you do with the lower level layer     */
  151.   /* that employs wn_create/wn_set/wn_destroy.                              */
  152.  
  153.  
  154.   set_idle_func(back_func);
  155.  
  156.   /* This tells UltraWin to do back_func() while waiting for an event,      */
  157.   /* which gives you the ablilty to do some background tasks if you wish!   */
  158.   /* In this case, were just outputting a string to all 8 windows.          */
  159.  
  160.  
  161.   wait_event();
  162.  
  163.   /* Simply tells UltraWin to wait for an event (a keypress since we did    */
  164.   /* not activate the mouse with init_mouse() after the init_video() call). */
  165.   /* Please note that we could have just as easily substitued the           */
  166.   /* "set_idle_func(back_func);wait_event();set_idle_func(NULL);" sequence  */
  167.   /* with a simple "while (!event_pending()) back_func();".  As a matter of */
  168.   /* fact, wait_event() is simply:                                          */
  169.   /*                                                                        */
  170.   /*  do                                                                    */
  171.   /*  {                                                                     */
  172.   /*    if( Idle_func != NULL )                                             */
  173.   /*      (*Idle_func)();                                                   */
  174.   /*  } while (!event_pending());                                           */
  175.  
  176.  
  177.   set_idle_func(NULL);
  178.  
  179.   /* This tells UltraWin to not do any background calls to an idle func,    */
  180.   /* which results in a "turning off" of the background tasks.              */
  181.  
  182.  
  183.   for (i=(MAX_WINDOWS - 1); i>=0; i--)
  184.     remove_window(&Win_array[i]);
  185.  
  186.   /* Take off each of the windows added, in reverse order for "nicety"!     */
  187.  
  188.  
  189.   remove_window(&Desk_window);
  190.  
  191.   /* Remove the desktop window from the linked list as well, prior to       */
  192.   /* exiting to DOS.                                                        */
  193.  
  194.  
  195.   end_video();
  196.  
  197.   /* This cleans up and resets the video mode that was active when you      */
  198.   /* first began the program.  Be sure to call this as the last function    */
  199.   /* before you return to DOS!                                              */
  200. }
  201. /*** end of main ***/
  202.  
  203. /*** END OF FILE ***/
  204.